package com.huaxia.service.excellent;

import com.huaxia.dao.*;
import com.huaxia.dao.excellent.*;
import com.huaxia.pojo.excellent.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Calendar;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/10 9:08
 */
@Service
public class ExcellentService {

    @Autowired
    private BranchMDRTMapper branchMDRTMapper;
    @Autowired
    private SaleDeptMDRTMapper saleDeptMDRTMpper;
    @Autowired
    private BranchFHSMapper branchFHSMapper;
    @Autowired
    private SaleDeptFHSMapper saleDeptFHSMapper;
    @Autowired
    private BranchQuarterFHSMapper branchQuarterFHSMapper;
    @Autowired
    private SaleDeptQuarterFHSMapper saleDeptQuarterFHSMapper;
    @Autowired
    private SalesDataMapper salesDataMapper;
    @Autowired
    private SzFHSMapper szFHSMapper;

    public List<BranchMDRT> getBranchMDRT(){
        Integer mdrtTarget = findMdrtTarget();
        return branchMDRTMapper.getBranchMDRT(mdrtTarget);
    }

    public List<SaleDeptMDRT> getSaleDeptMDRT(){
        Integer mdrtTarget = findMdrtTarget();
        return saleDeptMDRTMpper.getSaleDeptMDRT(mdrtTarget);
    }

    public List<BranchFHS> getBranchFHS(){return branchFHSMapper.getBranchFHS();}

    public List<SaleDeptFHS> getSaleDeptFHS(){return saleDeptFHSMapper.getSaleDeptFHS();}

    public List<SzFHS> getSzFHS(){return szFHSMapper.getSzFHS();}

    public List<BranchQuarterFHS> getBranchQuarterFHS(){
        int nowMonth = getNowMonth();
        if(nowMonth%3==1){
            return branchQuarterFHSMapper.getBranchQuarterFHS1();
        }
        if(nowMonth%3==2){
            return branchQuarterFHSMapper.getBranchQuarterFHS2();
        }
        if(nowMonth%3==0){
            return branchQuarterFHSMapper.getBranchQuarterFHS3();
        }
        return null;
    }
    public List<SaleDeptQuarterFHS> getSaleDeptQuarterFHS(){
        int nowMonth = getNowMonth();
        if(nowMonth%3==1){
            return saleDeptQuarterFHSMapper.getSaleDeptQuarterFHS1();
        }
        if(nowMonth%3==2){
            return saleDeptQuarterFHSMapper.getSaleDeptQuarterFHS2();
        }
        if(nowMonth%3==0){
            return saleDeptQuarterFHSMapper.getSaleDeptQuarterFHS3();
        }
        return null;
    }

    private int getNowMonth(){
        Calendar cal = Calendar.getInstance();
        return cal.get(Calendar.MONTH) + 1;
    }

    private Integer findMdrtTarget(){
        return salesDataMapper.findMdrtTarget();
    }


}
